﻿//********************************************************************************//
//创建日期：<创建日期，2017-8-17>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：月度复审修改
//********************************************************************************//
layui.use(['form', 'jquery', 'element', 'laydate'], function () {
    var form = layui.form()
    , layer = layui.layer
    , $ = layui.jquery
    , element = layui.element()
    , laydate = layui.laydate;
    var glkList = getGLKList("all", "");
    /*initial load start*/
    //var date = new Date();
    //var year = date.getFullYear();
    //var month = date.getMonth() + 1;
    //var day = date.getDate();
    //var rqstr = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
    //$("#cY").val(year);
    //$("#cM").val(month);
    var index = layer.load(1);
    initcontrol();
    //load();
    layer.close(index);

    /*initial load end*/

    /*initial*/
    function initcontrol() {
        //自来水需要加载左侧站点与管理块(当前未启用)
        //var wtype = getWType();
        loadControls(0);
        setUI(0);
    }
    function loadControls(wtype) {
        //加载站点
        $("#cZD option").remove();
        $("#cZD").append("<option value='0'>　</option>");
        var list = getZDList("all", "");
        for (var i = 0; i < list.length; i++) {
            $("#cZD").append("<option value='" + list[i]["Value"] + "'>" + list[i]["Text"] + "</option>");
        }        
        $("#cZD").get(0).selectedIndex = 0;      
        form.render("select");
    }
    function setUI(wtype) {
        if (wtype == 0) {
          
        }
        else {
          
        }
    }

    function load() {
        var zd = $("#cZD").val();
        var glk = $("#cGLK").val();
        var lhbh = $("#cLHBH").val();
        var yhh = $("#cYHH").val();
        //var y = $("#cY").val();
        //var m = $("#cM").val();
        var checkboxs = $("[name='cFS']:checked");
        if (checkboxs.length == 0) {
            layer.alert("至少选择一种复审状态");
            return;
        }
        //2种选中情况  1:已打印未打印均选中 查询全部用-1表示  2:查询1种(1:已打印 0:未打印)
        var fs = (checkboxs.length == 2) ? -1: (checkboxs.length == 1) ? $(checkboxs[0]).val() : -1;
        var rss = "";
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/LH/LaiHan.ashx",
            data: {
                "op": "FSLIST",
                "zd": zd=="0"?null:zd,
                "glk": glk=="0"?null:glk,
                "lhbh": lhbh,
                "yhh": yhh,
                "fs": fs
            },
            dataType: "json",
            success: function (rs) {
                rss = rs;
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
        $("#ContentList1").find(".datarow").remove();
        if (rss.length > 0) {
            chunk(rss, list1Create, bindListOperate);
        }
        else {
            $("#lsCount").text("0");
        }
    }
    function bindListOperate() {
        form.render("checkbox");
        //添加复审操作事件
        $("#ContentList1 .datarow").find("[iid='iFS']").click(function () {
            openEdit($(this).attr("vid"), $(this).attr("vid2"));
        });
    }
    function list1Create(rs, i) {
        $("#ContentList1").append(createItemStr1(rs,i+1));
        $("#lsCount").text($("#ContentList1 .datarow").length);
    }
    function createItemStr1(obj,no) {
        var str = $("#ItemStr1 tr").prop("outerHTML");
        var itemstr, lhbh, id, lhlx, xkslh, tyspbm, yhh, yhm, ym, djrq, spr, spjg, sprq, fszt;
        lhbh = obj["S_LAIHANBH"];
        id = obj["ID"];
        xkslh = obj["S_XUKEBH"];
        tyspbm = obj["S_TONGYIBM"];
        lhlx = obj["S_LAIHANLX"];
        yhh = obj["S_YONGHUBH"];
        yhm = obj["S_YONGHUM"];
        ym = obj["S_YM"];
        djrq = obj["D_SHURURQ"]["DateString"];
        spr = obj["S_SHENPIR"];
        spjg = obj["S_SHENPIJG"];
        sprq = obj["D_SHENPIRQ"]["DateString"];        
        fszt = obj["S_FUSHEN"];
        itemstr = str.replace(new RegExp("objNo", "gm"), no)
                        .replace(new RegExp("objLAIHANBH", "gm"), lhbh)
                        .replace(new RegExp("objID", "gm"), id)
                        .replace(new RegExp("objLAIHANLX", "gm"), lhlx)
                        .replace(new RegExp("objYHH", "gm"), yhh)
                        .replace(new RegExp("objYHM", "gm"), yhm)
                        .replace(new RegExp("objYM", "gm"), ym)
                        .replace(new RegExp("objDENGJIRQ", "gm"), djrq)
                        .replace(new RegExp("objSHENPIR", "gm"), spr)
                        .replace(new RegExp("objSHENPIJG", "gm"), spjg)
                        .replace(new RegExp("objSHENPISJ", "gm"), sprq)
                        .replace(new RegExp("objFUSHENZT", "gm"), fszt)
        ;
        return itemstr;
    }

    /*end initial*/

    /*event*/
    form.on('select(cZD)', function (data) {
        $("#cGLK option").remove();
        $("#cGLK").append("<option value='0'>　</option>");
        for (var i = 0; i < glkList.length; i++) {
            if (glkList[i]["ParentId"] == data.value) {
                $("#cGLK").append("<option value='" + glkList[i]["Value"] + "'>" + glkList[i]["Text"] + "</option>");
            }
        }
        $("#cGLK").get(0).selectedIndex = 0;
        form.render("select");
    });
    form.on("checkbox(selectAll)", function (data) {
        if (data.elem.checked) {
            $("#ContentList1 .datarow:visible").find("[name='liCheck']").prop("checked", "checked");
        }
        else {
            $("#ContentList1 .datarow:visible").find("[name='liCheck']").removeProp("checked");
        }
        form.render("checkbox");
        countSelected();
    });
    form.on("checkbox(liCheck)", function (data) {        
        countSelected();
    });
    $("#oSearch").click(function () {
        load();
    });
    //计算选中条数
    function countSelected() {
        $("#lsSelectedCount").text($("#ContentList1 .datarow:visible").find("[name='liCheck']:checked").length);
    }
    function openEdit(lhbh,id) {
        var url = "/Pages/YongShui/13.LaihanGL/YueDuTZFSXG.aspx?lhbh=" + lhbh +"&lhid="+id+ "&fs=fs";
        var width = "1000";
        var height = "560";
        layer.open({
            type: 2,
            title: "",
            shadeClose: false,
            shade: 0.8,
            area: [width + "px", height + "px"],
            content: url,
            end: function () {
                //load();
            }
        });
    }

    /*event end*/

    function verify() {
        return true;
    }

    /*logic end*/
});